/**
 * FileName: HandoverColler
 * Author:   秋水浮萍
 * Date:     2020/7/1 13:45
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.demo.controller;

import com.demo.model.HandoverName;
import com.demo.model.JsonMessage;
import com.demo.service.HandoverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author 秋水浮萍
 * @create 2020/7/1
 * @since 1.0.0
 */
@RestController
@Api(value = "员工交接接口")
@RequestMapping("/handover")
public class HandoverColler {
    @Autowired
    private HandoverService handoverService;

    /**
     * 所有员工
     * @return
     */
    @ApiOperation(value = "所有员工")
    @PostMapping("allName")
    public JsonMessage allName(){
        JsonMessage message=new JsonMessage();
        List<HandoverName> list=handoverService.allName();
        message.setData(list);
        return message;
    }

    /**
     * 交接
     * @return
     */
    @ApiOperation(value = "交接")
    @PostMapping("updateHandover")
    public JsonMessage updateHandover( String userValue,
                                        String userId){
        JsonMessage message=new JsonMessage();
        String[] split = userValue.split(",");
        if (split.length>0&&userValue!=null){
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            handoverService.updateHandover(split, userId, df.format(new Date()));
        }else {
            message.setData("无数据");
             }
        return message;
    }

    @ApiIgnore
    @PostMapping("updateUserId")
    public JsonMessage updateUserId(String updateUserId, String createUserId){
        JsonMessage message=new JsonMessage();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        handoverService.updateUserId(updateUserId,df.format(new Date()),createUserId);
        message.setData("ok");
        return message;
    }


}